import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDGuideText {
	/**编号*/
	id,
	/**所属引导--填写Guide id*/
	group,
	/**步骤，从小到大依次读取*/
	step,
	/**文本描述*/
	desc,
	/**解锁id*/
	unlockId,

	/**枚举数量*/
	EnumCount
}



export class CDGuideText{
	/**编号*/
	public id: number;
	/**所属引导--填写Guide id*/
	public group: number;
	/**步骤，从小到大依次读取*/
	public step: number;
	/**文本描述*/
	public desc: number[];
	/**解锁id*/
	public unlockId: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDGuideText.id: return this.id;
			case E_CDGuideText.group: return this.group;
			case E_CDGuideText.step: return this.step;
			case E_CDGuideText.desc: return this.desc;
			case E_CDGuideText.unlockId: return this.unlockId;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDGuideText.id: this.id = v; break;
			case E_CDGuideText.group: this.group = v; break;
			case E_CDGuideText.step: this.step = v; break;
			case E_CDGuideText.desc: this.desc = v; break;
			case E_CDGuideText.unlockId: this.unlockId = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDGuideText> = new HashMap<number, CDGuideText>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDGuideText[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDGuideText();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].group = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].step = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = [];
			const attrArray = list[i].desc;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].unlockId = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDGuideText{
		return this.datas ? this.datas.get(id) : null;
	}
}
